package com.xmall.order.controller.platform;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xmall.define.base.Result;
import com.xmall.order.define.dto.platform.OrderDtoForFront;
import com.xmall.order.define.dto.platform.OrderNumStatistics;
import com.xmall.order.define.request.query.FrontOrderListPageQueryRequest;
import com.xmall.order.service.platform.IOrderFrontService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 *  前端控制器
 */
@RestController
@RequestMapping("/service/order/api/front")
public class OrderFrontController {

    @Resource
    private IOrderFrontService orderFrontService;

    /**
     * 订单详情
     */
    @GetMapping("/info/{id}")
    public Result<OrderDtoForFront> info(@PathVariable("id") Long id) {
        return Result.success(orderFrontService.info(id));
    }

    /**
     * 订单详情
     */
    @GetMapping("/infoByOrderSn/{orderSn}")
    public Result<OrderDtoForFront> infoByOrderSn(@PathVariable("orderSn") String orderSn) {
        return Result.success(orderFrontService.infoByOrderSn(orderSn));
    }

    /**
     * 分页列表
     */
    @GetMapping("/listPage")
    public Result<Page<OrderDtoForFront>> listPage(@Validated FrontOrderListPageQueryRequest request){
        Page<OrderDtoForFront> pageList = orderFrontService.listPage(request);
        return Result.success(pageList);
    }

    /**
     * 不同状态订单数量
     */
    @GetMapping("/orderNumStatistics/{memberId}")
    public Result<OrderNumStatistics> orderNumStatistics(@PathVariable("memberId") Long memberId) {
        return Result.success(orderFrontService.orderNumStatistics(memberId));
    }
}
